package com.xuexiang.xuidemo.dialog;

import com.xuexiang.xuidemo.ResourceTable;

import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.PopupDialog;
import ohos.app.Context;

/**
 * 简单弹出框，对PopupDialog的简要封装
 *
 * @since 2021-04-22
 */
public class EasyPopupDialog extends PopupDialog {
    //private Context mContext;
    private PopDestroyedListener mPopDestroyedListener;
    private Component component;
    private Text tv_zna, tv_comment;

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param contentComponent 组件
     */
    public EasyPopupDialog(Context context, Component contentComponent) {
        super(context, contentComponent);
        //this.mContext = context;
        component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_easy_popup_layout, null, true);
        tv_zna = (Text) component.findComponentById(ResourceTable.Id_tv_zan);
        tv_comment = (Text) component.findComponentById(ResourceTable.Id_tv_comment);
        setCustomComponent(component);
    }

    /**
     * 点赞监听
     *
     * @param mClickedListener
     */
    public void setBtnznaClickedListener(Component.ClickedListener mClickedListener) {
        tv_zna.setClickedListener(mClickedListener);
    }

    /**
     * 评论监听
     *
     * @param mClickedListener
     */
    public void setBtncomlClickedListener(Component.ClickedListener mClickedListener) {
        tv_comment.setClickedListener(mClickedListener);
    }

    /**
     * 销毁监听
     *
     * @param popDestroyedListener 销毁接口实例
     */
    public void setDestroyedListener(EasyPopupDialog.PopDestroyedListener popDestroyedListener) {
        this.mPopDestroyedListener = popDestroyedListener;
    }

    /**
     * pop销毁
     */
    protected void onDestroy() {
        super.onDestroy();
        if (mPopDestroyedListener != null) {
            mPopDestroyedListener.onPopDestroy();
        }
    }

    /**
     * 自定义销毁监听接口
     *
     * @since 2021-04-21
     */
    public interface PopDestroyedListener {
        /**
         * pop消失监听
         */
        void onPopDestroy();
    }
}
